home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TDE.ARJ
/
TDE.MAN
< prev
next >
Wrap
Text File
|
1992-07-14
|
10KB
|
228 lines
FILENAME: TDE.MAN
*****************
Class TDataEntry v1.0 - 07/14/92
--------------------------------
----------------------------------------------------------------------------
Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
----------------------------------------------------------------------------
A data entry class for Borland's Turbo Vision, derived from TInputLine.
Copyright Notice
================
As this material is ultimately derived from Borland source files, any of
their copyrights which MAY apply DO apply.
From the author's standpoint, you may use this material freely and,
hopefully, post any comments/corrections/enhancements to me at the above-
noted addresses. I do ask that you not distribute this material except as
originally received, including all source/documentation files in their
original form.
If you DO modify or enhance any of this code, please send any such changes
to me for incorporation into a future version. Any such enhancements will
be DONATED, without expectation of compensation or incorporation into
future versions. Again, if you distribute this code, please do so in its
original, unmodified form including all source files and documentation.
Source files included
=====================
TDE .DOC: This documentation.
TDE .MAN: How to use TDataEntry in your dialog objects
TDE .H : header file containing class declarations for classes
TDEFLAGS.H : " " " flags and command definitions
TDE .CPP: Class TDataEntry
TDEDATE .CPP: Class TDEDate
TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
TDENUMS .CPP: Class TDEInteger
TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
TDELIB .PRJ: Project for building library TDELIB.LIB
TDEDEMO .CPP: Demo program
TDEDEMO .PRJ: Project for building TDEDEMO.EXE
***************************************************************************
How to use class TDataEntry in your Applications
================================================
BUILD THE LIBRARY
-----------------
The project file TDELIB.PRJ is included. It assumes that all the source
is in the current directory. Before using, update Options|Directories
to reflect the appropriate paths. It builds the library TDELIB.LIB.
If you like TDataEntry and want to use it in your applications, you
can build an overlaid version of the library by studying the compiler
options in Borlands makefile for TV.LIB. In particular, you've got to
set the Compile via Assembler, Local Virtual Tables, etc. options.
USE THE LIBRARY
---------------
1) You'll probably want to put both TDE.H and TDEFLAGS.H in your
TVISION\INCLUDE directory or whatever directory you keep your .h
files in and which is listed in your project's directory list.
2) You need to #include TDE.H in any file which uses TDataEntry objects.
(TDEFLAGS.H is brought in by TDE.H, so you don't have to #include it.)
Before #include'ing TDE.H, #define the appropriate Uses_XXXXXX
for the TDataEntry classes which you'll be using. Consult TDE.H for
the Uses_XXXXX definitions to use. (This method is a blatant rip-off
of Borland's method, but it simplifies things and works so well!)
3) Somewhere before calling TApplication.run(), set the static
TDataEntry members if you want non-default global behavior.
4) Dialog Box Construction:
When constructing a dialog box, you should set TDataEntry::globaID = 0
BEFORE inserting any TDataEntry objects. This will ensure that the
objects are numbered starting at 1. You don't need to do this if you
won't be using the TDataEntry::locateID() function, but it's best to
since the code hasn't been tested in the case where TDataEntry::globalID
exceeds MAX_UCHAR (255). Theoretically, all fields will be assigned
the number 255 when TDataEntry::globalID hits 255.
Insert TDataEntry objects as you would any other objects, paying
attention to constructor syntax (you DON'T specify field length when
you specify a format). The default for fieldName is NULL, so if you
leave it off no field name will be assigned.
If you want to modify the field's localMode member, you must get a
pointer to the object, then access localMode through the pointer:
.......
TView *v; (real generic so you can use it with anything you insert)
TDataEntry::globalID = 0;
insert((v = new TDEDate( 2, 4, "~~/~~/~~", "myField")));
//* The TDEDate object uses TDEData::defCentury for the century and uses
//* MM/DD/YY format by default. The field has been assigned the name
//* 'myField'
((TDataEntry *)v)->localMode |= (tdlAutoExit | tdlRequired);
//* The object will exit automatically when the last digit is entered
//* and validation will require that this field be non-blank.
......
Be sure to use the TDEButton, TDEInputLine, TDERadioButtons, and
TDECheckBoxes objects instead of the standard ones. These objects
behave in a manner consistent with TDataEntry object behavior and, in
addition, respond to some of TDataEntry's query functions.
5) THAT'S IT! THE REST IS UP TO YOU. You'll probably want to use some
of TDataEntry's query functions prior to allowing a dialog to close.
Your dialog's valid() function should call TDataEntry::queryChanged()
when it gets cmClose/cmCancel/cmQuit messages. Prior to saving data,
you'll want to call TDataEntry::queryValid() to verify data integrity
before committing it to disk. ( REMEMBER: inter-field movement via
mouse does NOT perform field validation, so bad data can slip through
during data entry )
6) ONE MORE THING: Don't forget to add TDELIB.LIB to your project!
USING THistory with TDataEntry objects
======================================
The problem with using THistory with TDataEntry objects is twofold:
a) If TDataEntry::globalMode's tdgUpDownEnable flag is set, then a
kbDown event will not be seen by THistory, preventing it from
responding.
b) THistory assumes it's attached to a TInputLine object. When it
calls selectAll() upon close, it calls TInputLine's selectAll()
rather than TDataEntry's [selectAll() is not virtual in TInputLine].
In addition, you may not want the data to be selected anyway, pre-
ferring that it act according to TDataEntry::globalMode's
tdgSelectOnFocus flag.
The solution is as follows: You MUST derive a THistory object that's
TDataEntry-friendly. In addition, if you have the TDataEntry::globalMode
tdgUpDownEnable flag set, you must derive a new TDataEntry object. It's
best to do both so that everything works later if your project's design
changes. Fortunately, both of these solutions are simple:
A) DERIVE A NEW TDataEntry OBJECT
---------------------------------
class TNumLookup : public TDENumeric //* or some other TDataEntry object
{
public:
//* I've only defined a constructor using TDE's CONSTRUCTOR 2
//* You can define either one or both as needed
TNumLookup(int x, int y, int w, const char *fName = NULL) :
TDENumeric( x, y, w, fName ) {};
virtual void handleEvent( TEvent& event );
};
void TNumLookup::handleEvent( TEvent& event )
{
TView::handleEvent(event);
if ( event.what == evKeyDown && event.keyDown.keyCode == kbDown )
return; //** let TTarHistory grab this one
TDENumeric::handleEvent( event );
}
B) DERIVE A NEW THistory OBJECT
-------------------------------
class TDEHistory : public THistory
{
public:
TDEHistory(const TRect& bounds, TInputLine *aLink, ushort aHistoryId) :
THistory( bounds, aLink, aHistoryId ) {};
virtual void handleEvent(TEvent& event);
private: //* necessary because THistory's icon is private
static const char * near icon;
};
const char * near TTarHistory::icon = "\xDE~\x19~\xDD";
void TDEHistory::handleEvent( TEvent& event )
{
THistoryWindow *historyWindow;
TRect r, p;
ushort c;
TView::handleEvent( event );
if( event.what == evMouseDown ||
(event.what == evKeyDown &&
ctrlToArrow( event.keyDown.keyCode ) == kbDown &&
(link->state & sfFocused) != 0)
)
{
link->select();
historyAdd( historyId, link->data );
r = link->getBounds();
r.a.x--; r.b.x++; r.b.y += 7; r.a.y--;
p = owner->getExtent();
r.intersect( p );
r.b.y--;
historyWindow = initHistoryWindow( r );
if( historyWindow != 0 )
{
c = owner->execView( historyWindow );
if( c == cmOK )
{
char rslt[256];
historyWindow->getSelection( rslt ); //** JDP
((TDataEntry *)link)->setData(rslt);
// strncpy( link->data, rslt, link->maxLen );
if ( (TDataEntry::globalMode & tdgSelectOnFocus) != 0 )
((TDataEntry *)link)->selectAll( True );
((TDataEntry *)link)->drawView();
}
destroy( historyWindow );
}
clearEvent( event );
}
else
THistory::handleEvent(event);
}
//******************** TDE.MAN ends *******************************//